 <?php foreach ($role_data as $key): ?>
    <form class="form-horizontal" id="edit_role_form">
        <div class="ibox float-e-margins">
            <div class="ibox-title" style="border: none;">
                <h5 style="color: #00afef"><i>Roles</i></h5>
                <div class="ibox-tools" id="add_btn">
                    <i id="loading_role_btn_edit" style="color: gray; display: none;" class="fa fa-spinner fa-spin fa-lg"></i>&nbsp;
                    <button class="btn btn-primary btn-sm save-btn-tab" id="edit_role_btn">Save</button>
                    <a id="edit_cancel" class="btn-outline btn btn-info btn-sm cancel-btn-tab" >Cancel</a>
                </div>
            </div>
            <div class="ibox-content">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Company</label>
                        <div class="col-lg-5">
                            <input type="hidden" name="role_id" value="<?php echo $key->role_id; ?>">
                            <input readonly type="text" class="form-control" name="role_company" value="<?php echo $key->company_name; ?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Name</label>
                        <div class="col-lg-5">
                            <input value="<?php echo $key->role_name; ?>" type="text" class="form-control" name="role_name_e">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Description</label>
                        <div class="col-lg-5">
                            <input type="text" class="form-control" name="role_description_e" value="<?php echo $key->description; ?>">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">Enable</label>
                        <div class="col-lg-1">
                            <input type="checkbox" class="i-checks" name="role_status_e" value="ok" <?php echo $key->enable_flag == 'Y' ? 'checked' : ''; ?>>
                        </div>
                    </div>
                </form>
            </div>
            <div class="ibox-content">
                <button type="button" class="btn btn-primary add-tab-btn" id="role_dtl_modal2" >New Detail</button>
                <table class="dataTable2 table table-bordered table-compact">
                    <thead>
                        <tr>
                            <th>Form</th>
                            <th>Module</th>
                            <th style="border-right: none;">Create</th>
                            <th style="border-right: none; border-left: none;">Update</th>
                            <th style="border-right: none; border-left: none;">Delete</th>
                            <th style="border-left: none;">ReadOnly</th>
                            <th>Enabled</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody id="role-dtl-tbl-edit">

                    </tbody>
                </table>
            </div>
        </div>
<?php endforeach;?>
<script type="text/javascript">
    $(document).ready(function() {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $("#edit_role_form").validate({
                 rules: {
                     role_status: {
                        required: true
                     },
                     role_name: {
                        required : true
                     }
                 },
                 submitHandler: function(form){
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url($this->session->userdata('forajax') . '/editRole'); ?>",
                        data: $('#edit_role_form').serialize(),
                        dataType: 'json',
                        success: function(e){
                            $('#edit_role_btn').removeAttr('disabled');
                            $('#loading_role_btn_edit').hide();
                            console.log(e);
                            if(e[0].error == 1){
                                notifymsg('danger','<b>Error</b>: ' + e[0].msg);
                                $('input[name=role_name]').addClass('error');
                                $('#role_name-error').show();
                            }else{
                                $('#role_name-error').hide();
                                notifymsg('success','<b>Success</b>: Data Saved');
                                localStorage.role_id_e = e[0].id;
                                counter = 1;
                            }
                        },
                        beforeSend: function(){
                            $('#edit_role_btn').attr('disabled', true);
                            $('#loading_role_btn_edit').show();
                        }
                    });
                 }
        });
        $('#edit_cancel').click(function(){
            console.log(swal);
                swal({
                    title: "Are you sure?",
                    text: "You want to leave this page?",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Yes, Please.",
                    cancelButtonText: "No, I'll Stay",
                    closeOnConfirm: true,
                    closeOnCancel: true },
                function (isConfirm) {
                    if (isConfirm) {
                        $('#tab-list-2 a:first').tab('show');
                        $('#edit').remove();
                        $('#edit-link').remove();
                        $('#count_edit').val('0');
                    } else {
                    }
                });
             console.log(swal());
        });
    });
</script>